const webpack = require('webpack'),
  path = require('path'),
  autoprefixer = require('autoprefixer'),
  webpackConfig = require('./config.base'),
  ProgressBarPlugin = require('progress-bar-webpack-plugin'),
  config = require('./const')

webpackConfig.devServer = {
  host: '0.0.0.0',
  inline: true,
  disableHostCheck: true,
  port: 10000,
  contentBase: path.join(__dirname, '..', 'dist/'),
  proxy: {
    '/api': {
      target: 'http://localhost:9090',      // 转发mock请求
      secure: false
    }
  }
}

webpackConfig.module.rules.push({
  test: /\.css$/,
  use: ['style-loader', 'css-loader', 'postcss-loader']
})

webpackConfig.module.rules.push({
  test: /\.scss$/,
  use: ['style-loader', 'css-loader', 'autoprefixer-loader', 'sass-loader?sourceMap']
})

webpackConfig.module.rules.push({
  test: /\.(js|jsx)$/,
  exclude: /node_modules/,
  loader: 'babel-loader',
  options: {
    presets: ['es2015', 'react', 'stage-0', 'react-hmre'],
    plugins: ['transform-runtime', 'add-module-exports', 'transform-decorators-legacy'],
    cacheDirectory: true
  }
})

webpackConfig.plugins.push(
  new webpack.DefinePlugin({'process.env': {NODE_ENV: JSON.stringify('development')}})
)

webpackConfig.plugins.push(new ProgressBarPlugin({summary: false}))

module.exports = webpackConfig
